/**
 * @(#) ProfileProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 인사기록 조회 - Proxy
 * 				인사기록을 조회하는 Model Logic 
 */
package com.skt.common_hr.mintview.model
{
	
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.mintview.MintViewFacade;
	import com.skt.common_hr.mintview.model.vo.mintListVO;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class PrivateListProxy extends CommonProxy
	{
		public static const NAME:String = "PrivateListProxy";
		
		public var mintListArr:ArrayCollection;
		public var rowCount:int;


		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function PrivateListProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, viewr:String, sDay:Date, eDay:Date):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;//"1100021";
			param["I_VIEWR"] = viewr;//"1100021";
			param["I_BEGDA"] = DateUtil.toBasicString(sDay);
			param["I_ENDDA"] = DateUtil.toBasicString(eDay);
			loadData("Z_HR_IN06", param, result, fault); 
		}
		
		public function loadBtnChk(pernr:String, viewr:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;//"1100021";
			param["I_VIEWR"] = viewr;//"1100021";
			loadData("Z_HR_IN08", param, resultChk, fault); 
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				mintListArr = parseMintList(event.result.T_OUT);
				
				facade.sendNotification(MintViewFacade.LOAD_PRIVATELIST_COMPLETE, this);
			}
			else {
				trace( "failed to load profile: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				facade.sendNotification(MintViewFacade.LOAD_MEMBERSEARCH_COMPLETE, this);
			}
		}
		
		public function resultChk(event:ResultEvent):void
		{
			if(retCode==0) {  
				facade.sendNotification(MintViewFacade.LOAD_BTNCHECK_COMPLETE, this);
			}
			else {
				trace( "failed to load profile: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				facade.sendNotification(MintViewFacade.LOAD_BTNCHECK_FAILED, this);
			}
		}
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			trace("Fault message in ProfileProxy: " + event.fault.faultString);
			facade.sendNotification(MintViewFacade.LOAD_PROFILE_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 인사기록 Value Object
		 */
		private function parseMintList(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			for(var i:int = 0; i < srcArr.length; i++) 
			{
				
				var vo:mintListVO = new mintListVO();
				vo.AEDTM		= DateUtil.stringToDateTime(srcArr[i].AEDTM);
				vo.CDATE		= DateUtil.stringToDateTime(srcArr[i].CDATE);
				vo.CTIME		= DateUtil.stringToDateTime(srcArr[i].CTIME);
				vo.DATUM		= DateUtil.stringToDateTime(srcArr[i].DATUM);
				vo.ENAME 		= srcArr[i].ENAME;
				vo.ETIME		= DateUtil.stringToDateTime(srcArr[i].ETIME);
				vo.JINFO 		= srcArr[i].JINFO;
				vo.MANDT		= srcArr[i].MANDT;
				vo.MFLAG 		= srcArr[i].MFLAG;
				vo.ORGTX 		= srcArr[i].ORGTX;
				vo.PERNR 		= srcArr[i].PERNR;
				vo.SEQNR 		= srcArr[i].SEQNR;
				vo.SRTFD 		= srcArr[i].SRTFD;
				
				vo.STIME		= DateUtil.stringToDateTime(srcArr[i].STIME);
				vo.TITLE 		= srcArr[i].TITLE;
				vo.UZEIT		= DateUtil.stringToDateTime(srcArr[i].UZEIT);
				vo.VIEWR 		= srcArr[i].VIEWR;
				vo.VNAME		= srcArr[i].VNAME;
				
				// 변경삭제 유무 
				if(vo.MFLAG == 'X' && vo.MFLAG == null&& vo.MFLAG == ""){
//					vo.MFLAG = true;
				} else {
//					vo.MFLAG = false;
				}	
				
				retArr.addItem(vo);
			}
			rowCount = (i==0)?1:i;
			return retArr;	
		}
		
		
	}
}